<template>
	<view class="content">
		<u-grid :col="3">
			<u-grid-item @click="chooseImage">
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片选择</view>
			</u-grid-item>
			<u-grid-item @click="viewImages">
				<u-icon name="photo" :size="46"></u-icon>
				<view class="grid-text">图片预览</view>
			</u-grid-item>
			<u-grid-item @click="formateDate">
				<u-icon name="hourglass" :size="46"></u-icon>
				<view class="grid-text">格式化时间</view>
			</u-grid-item>
			<u-grid-item @click="createGuid">
				<u-icon name="file-text-fill" :size="46"></u-icon>
				<view class="grid-text">生成唯一标识</view>
			</u-grid-item>
			<u-grid-item @click="routerTest">
				<u-icon name="arrow-right" :size="46"></u-icon>
				<view class="grid-text">路由方法</view>
			</u-grid-item>

			<u-grid-item @click="pushFullScreen">
				<u-icon name="list-dot" :size="46"></u-icon>
				<view class="grid-text">全屏窗口</view>
			</u-grid-item>
			<u-grid-item @click="pushMessage">
				<u-icon name="bell" :size="46"></u-icon>
				<view class="grid-text">消息推送</view>
				<u-modal v-model="show" :content="content"></u-modal>
			</u-grid-item>
		</u-grid>
	</view>
</template>

<script>
import MessagePush from '@/common/message.push.js';

export default {
	data() {
		return {
			show: false,
			prevImages: [],
			content: '请在手机端测试',
			push: null
		};
	},
	onLoad() {},
	methods: {
		pushMessage() {
			// #ifdef APP-PLUS
			this.push = new MessagePush();
			const client = this.push.getClientInfo();
			console.log(client)
			this.push.createMessage('测试消息推送','测试消息推送','/static/Nr304OPr3m.png');
			this.push.clickMessage(res => {
				console.log(res);
				uni.showModal({
					content:JSON.stringify(res)
				})
			});
			// #endif

			// #ifdef H5
			this.show = true;
			// #endif
		},
		pushFullScreen() {
			this.$u.route('/pages/fullscreen/fullscreen');
		},
		routerTest() {
			this.$routers.push('/pages/guide/guide');
		},
		createGuid() {
			uni.showModal({
				content: JSON.stringify(this.$createGuid() + '或者' + this.$u.guid())
			});
		},
		formateDate() {
			uni.showModal({
				content: JSON.stringify(this.$formatTime(new Date()))
			});
		},
		chooseImage() {
			this.$chooseImages(2)
				.then(res => {
					this.prevImages = res.tempFilePaths;
					uni.showModal({
						content: JSON.stringify(res)
					});
				})
				.catch(err => {
					uni.showModal({
						content: JSON.stringify(err)
					});
				});
		},
		async viewImages() {
			this.$chooseImages(9)
				.then(res => {
					this.prevImages = res.tempFilePaths;
					this.$previewImages(this.prevImages)
						.then(res => {
							uni.showModal({
								content: JSON.stringify(res)
							});
						})
						.catch(err => {
							uni.showModal({
								content: JSON.stringify(err)
							});
						});
				})
				.catch(err => {
					uni.showModal({
						content: JSON.stringify(err)
					});
				});
		}
	}
};
</script>

<style lang="scss" scoped></style>
